package com.hualan.sfzy.service.impl.consult;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.consult.ConsultChargesClassifyMapper;
import com.hualan.sfzy.mapper.consult.ConsultChargesMapper;
import com.hualan.sfzy.model.entity.ConsultCharges;
import com.hualan.sfzy.model.entity.ConsultChargesClassify;
import com.hualan.sfzy.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ConsultChargesClassifyServiceImpl implements BaseService<ConsultChargesClassify> {
    @Autowired
    private ConsultChargesClassifyMapper mapper;
    @Autowired
    private ConsultChargesMapper chargesMapper;

    @Override
    public int add(ConsultChargesClassify entity) {
        return mapper.insert(entity);
    }

    @Override
    public int edit(ConsultChargesClassify entity) {
        return mapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        // 首先判断是否还有咨询师在使用这个收费分类标准
        List<ConsultCharges> list = chargesMapper.selectPro(id);
        if (list.size() > 0) {
            throw new RuntimeException("该收费分类标准下有咨询师在使用，暂时不能删除");
        }
        return mapper.delete(id);
    }

    @Override
    // 没有批量删除
    public int removeBatch(Integer[] ids) {
        return 0;
    }

    @Override
    public List<ConsultChargesClassify> find() {
        return mapper.select(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, ConsultChargesClassify entity) {
        PageHelper.startPage(pageNum, pageSize);
        List<ConsultChargesClassify> list = mapper.select(entity);
        PageInfo<ConsultChargesClassify> info = new PageInfo<>(list);
        Map<String, Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, info.getPages());
        map.put(CommonConstant.TOTAL, info.getTotal());
        return map;
    }

    @Override
    public ConsultChargesClassify findById(Integer id) {
        return mapper.selectById(id);
    }
}
